/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.solitaire.web.controller.manager;

import com.medusa.gruul.common.core.util.PageUtils;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.solitaire.api.model.dto.manager.InformationInfoDto;
import com.medusa.gruul.solitaire.api.model.param.manager.InformationInfoParam;
import com.medusa.gruul.solitaire.api.model.vo.manager.InformationInfoVo;
import com.medusa.gruul.solitaire.service.manager.IInformationInfoService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 资讯信息信息 前端控制器
 * </p>
 *
 * @author lcysike
 * @since 2021-05-26
 */
@RestController
@RequestMapping("/manager/information/info")
public class InformationInfoController {

    @Autowired
    private IInformationInfoService iInformationInfoService;

    /**
     * 获取资讯列表信息
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取资讯列表信息")
    public Result<PageUtils<InformationInfoVo>> list(InformationInfoParam informationInfoParam) {
        PageUtils<InformationInfoVo> pageUtils = new PageUtils(iInformationInfoService.list(informationInfoParam));
        return Result.ok(pageUtils);
    }

    /**
     * 获取单条资讯信息
     */
    @GetMapping("/get/{id}")
    @ApiOperation(value = "获取单条资讯信息")
    public Result<InformationInfoVo> get(@ApiParam(value = "资讯信息id", required = true) @PathVariable(name = "id") Long id) {
        InformationInfoVo informationInfoVo = iInformationInfoService.get(id);
        return Result.ok(informationInfoVo);
    }

    /**
     * 资讯信息新增/修改
     */
    @PostMapping("/save")
    @ApiOperation(value = "资讯信息新增/修改")
    public Result save(@RequestBody @Validated InformationInfoDto informationInfoDto) {
        iInformationInfoService.save(informationInfoDto);
        return Result.ok();
    }


    /**
     * 资讯信息排序
     */
    @PutMapping("/sort")
    @ApiOperation(value = "资讯信息排序")
    public Result sort(@RequestBody List<InformationInfoDto> informationInfoDtos) {
        iInformationInfoService.sort(informationInfoDtos);
        return Result.ok();
    }

    /**
     * 资讯信息删除
     */
    @DeleteMapping("/delete/{ids}")
    @ApiOperation(value = "资讯信息删除")
    public Result delete(@ApiParam(value = "资讯专题ids", required = true) @PathVariable(name = "ids") Long[] ids) {
        iInformationInfoService.delete(ids);
        return Result.ok();
    }
}
